<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
	<head>
		<style type="text/css">
* {
}

.div {
	height: 350px;
	width: 460px;
	border: 1px solid #F96;
}

.div div {
	border: 1px solid #C30;
}

.divtop {
	height:260px;
	border:0;
	border-bottom-width:0px;
	border-style:solid;
	border-color: #FC6;
	margin-top: 33px;
	width:390px;
	font-family: "微软雅黑";
	font-size:12px;
	color:#999;
	
}
.tab{
	background-image:url(/chat/images/lltbj.jpg);
	background-repeat:no-repeat;
	border:solid 0px;
	border-color:#999;
	}
.bt{
	background-color:#FFF;
	background-repeat:no-repeat;
	width:90px;
	height:25px;
	border:none;
	margin-left:290px
}
.divdow {
	height: 20%;
	margin: 0px 0px;
}
        </style>
		<script src="<%=basePath%>js/jquery.js"></script>
</head>
	<body>
	<script type="text/javascript">
  	$.post("/chat/chat_loadServer.action",function(message){
  		$("#server").html(message);
  	});
  </script>
		<table width="390px" class="tab" height="410px">
				<tr>
					<td>
			
							<div id="message" class="divtop">
							</div>

					
					
			    

		<script type="text/javascript">
  				function question(){
  					 var user = $("#user").val();
  					 var question = $("#question").val();
  					 if(user == null || user == ""){
  					 	user = "y";
  					 }
  					if(question != ""){
  						$.post("<%=basePath%>chat_question.action",{user:encodeURIComponent(user),question:encodeURIComponent(question)},function(d){
  							$("#message").html(d);
  						});
  					}
  				}
  				function showMessage(){
  					var user = $("#user").val();
		  			$.post("<%=basePath%>chat_reqUser.action",{user:encodeURIComponent(user)}, function(html){
					    $("#message").html(html);
					  }); 
		  		}
		  		setInterval("showMessage()","3000");
  			</script>
				  </td>
				</tr>
				<tr>
				  <td>					
 <button onclick="ssss()" class="bt">
         <img src="/chat/images/liaotxq.png"/></button>
				  <div id="jilu"></div></td>
		  </tr>
				<tr>
				  <td>	<div class="divdow">
<input type="text" style="width:390px; height:20px; background-color: #FFF; border-width:1px; border-style:solid; text-align:left; vertical-align: text-top; border-color: #09F;" id="question" />
                     <div>
<button style="border:none; height:20px; margin-bottom:-20px; margin-left:220px; background-color:#FFF;" >
                    <img src="/chat/images/qx.png" width="67"  height="20" />
                    </button>
                    
                    <button  onclick="javascript:question()" style="border:none; height:20px; margin-left:310px; background-color:#FFF;" >
<img src="/chat/images/tw.png" alt="提问"  width="67" height="20" title="提问" /></button>
</div>
									 <input style="position: absolute" type="hidden" id="user" name="user" value='${user == null ? "y" : user }' /> 
                                     </div>
				  </td>
		  </tr>
	
		</table>
        
		<script type="text/javascript">
   			window.onbeforeunload = function(event){
				event = event || window.event;
				event.returnValue = "确定关闭?";
				var user = $("#user").val();
				writeFile(user);
			}
			function writeFile(user){ 
				//设置两个cookie
				$.post("/chat/chat_reqUser.action",{user:user},function(message){
					var m = message;
					//使用escape()方法编码  
					//使用unescape()方法解码  
					var date=new Date();
					var expireDays=10;
					date.setTime(date.getTime()+expireDays*24*3600*1000);
					//每次关闭页面时保存 聊天信息
					var s = escape(getCookie(user)) + m;
					setCookie(user,s,date);
					$.post("/chat/chat_delUserMessage.action",{user:encodeURIComponent(user)},function(d){
    				});
				});
			}
			function setCookie(name, value, expires){ 
				var curcookie = name + "=" +value 
				+ ((expires) ? ";expires=" + expires.toGMTString() : "") 
				+ ";path=/chat"; 
				document.cookie = curcookie; 
			} 
			function getCookie(){ 
				var name = $("#user").val();
				var s ="";
				if(document.cookie.length > 0){ 
				start = document.cookie.indexOf(name + "="); 
					if( start != -1){ 
						start = start +name.length + 1; 
						end = document.cookie.indexOf(";",start); 
						if( end == -1){ 
							end = document.cookie.length; 
						} 
						s = unescape(document.cookie.substring(start,end)); 
						if("null"==s){s="";}
					} 
				} 
				return s;
			}
			function ssss(){
				var user = $("#user").val();
				var s = getCookie();
				//alert(s);
				document.getElementById("jilu").innerHTML = s;
				//$("#jilu").html(s);
			}
    </script>
	</body>
</html>
